﻿using DotNetCore.CAP;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

namespace NoticeWechat.Subscribe
{
    public static class SubscribeRunner
    {
        public static IServiceCollection AddSubscribe([NotNull] this IServiceCollection services)
        {
            Type[] types = Assembly.GetEntryAssembly().GetTypes();
            foreach (Type targetType in types)
            {
                if (targetType.GetInterfaces().Contains(typeof(ICapSubscribe)))
                {
                    services.AddTransient(typeof(ICapSubscribe),targetType);
                }
            }
            return services;
        } 
    }
}
